import nyNetwork from "@/api/nyBaseNetwork";
import DZAnswerType from "@/config/DZAnswerType";
import DZModelAnswer from "../model/DZModelAnswer";
import DZModelQuestion from "../model/DZModelQuestion";

class DZServiceQuestion {

    assess = "";

    key_question = "";

    list_question: Array<DZModelQuestion> = []

    m_question = new DZModelQuestion();

    select_item_id = "";

    list_answer: Array<DZModelAnswer> = [];

    m_answer = new DZModelAnswer();

    list_anser_type = DZAnswerType;

    net_list_question() {
        var list_data = [];
        nyNetwork.net("问题列表", { assess: this.assess, name: this.key_question }, data => {
            for (const item of data) {
                var question = new DZModelQuestion();
                question.id = item.iId;
                question.info = item.sInfo;
                list_data.push(question);
            }
            this.list_question = list_data;
        })
    }

    net_add_question(success: () => void) {
        nyNetwork.net("添加问题", { assess: this.assess, info: this.m_question.info }, data => {
            success();
        })
    }

    net_edit_question(success: () => void) {
        nyNetwork.net("修改问题", { id: this.m_question.id, info: this.m_question.info }, data => {
            success();
        })
    }

    net_list_answer() {
        var list_data = [];
        nyNetwork.net("答案列表", { question: this.select_item_id }, data => {
            for (const item of data) {
                var answer = new DZModelAnswer();
                answer.id = item.iId;
                answer.info = item.sInfo;
                answer.score = item.sScore;
                list_data.push(answer);
            }
            this.list_answer = list_data;
        })
    }

    net_add_answer(success: () => void) {
        nyNetwork.net("添加答案", { question: this.select_item_id, info: this.m_answer.info, score: this.m_answer.score }, data => {
            success();
        })
    }
    net_edit_answer(success: () => void) {
        nyNetwork.net("编辑答案", { id: this.m_answer.id, info: this.m_answer.info, score: this.m_answer.score }, data => {
            success();
        })
    }


}
export default DZServiceQuestion;